<template>
  <div class="app-container">
    <div class="app-title">
      <span>信息功能控制</span>
    </div>
    <div class="filter-container">
      <el-row>
        <el-form ref="dataForm" :model="formData" label-position="right" label-width="100px" size="small">
          <el-row />
          <div class="contentBorder" :style="'height : ' + tableHeight + 'px'">
            <div :style="'padding-top: ' + (tableHeight * 0.3) + 'px'">
              <div>
                是否校验附件：
                <el-switch v-model="fileVerify" inactive-text="关" active-text="开">
                </el-switch><br><br>
              </div>
              <div>
                为0上传：
                <el-switch v-model="zeroAble" inactive-text="关" active-text="开">
                </el-switch><br><br>
              </div>

              <div>
                开启支出功能科目：
                <el-switch v-model="funcName" inactive-text="关" active-text="开">
                </el-switch><br><br>
              </div>
              <div>
                绩效金额控制上报：
                <el-switch v-model="meritPay" inactive-text="关" active-text="开">
                </el-switch><br><br>
              </div>
              <!-- <div>
                 多批次为0上传：
                <el-switch
                  v-model="zeroAbles"
                  inactive-text="关"
                  active-text="开">
                </el-switch>
               </div> -->

              <el-button size="small" class="filter-item move"
                :style="'position: relative; left: 12%; margin-left: 1px ;margin-top: ' + (tableHeight * 0.1) + 'px'"
                type="primary" :loading="toUpdateLoading" @click="toUpdate">
                保存
              </el-button>

              <el-button size="small" class="filter-item move"
                :style="'position: relative;left: 15%;top: 60px; margin-left: 1px ;margin-top: ' + (tableHeight * 0.2) + 'px'"
                type="primary" :loading="deleteRedisLoading" @click="deleteRedis('generateSalary')">
                解除生成工资数据执行锁
              </el-button>
              <el-button size="small" class="filter-item move"
                :style="'position: relative;left: 20%;top: 60px; margin-left: 1px ;margin-top: ' + (tableHeight * 0.2) + 'px'"
                type="primary" :loading="deleteRedisLoading" @click="deleteRedis('lunarKnot')">
                解除月结执行锁
              </el-button>
            </div>

          </div>
        </el-form>
      </el-row>
    </div>
  </div>
</template>

<script>
import {
  getSalaryConfig,
  updataGetSalaryConfig,
  deleteRedis
} from '@/api/salaryFunctionController/salaryFunctionController'

export default {
  name: 'functionControl',
  data() {
    return {
      checkAccessory: false,
      tableHeight: null,
      listLoading: true,
      toUpdateLoading: false,
      zeroAble: '',
      meritPay: '',

      fileVerify: '',
      funcName: '',
      formData: {
        configType: '',
        isAble: ''
      },
      deleteRedisLoading: false,
    }
  },
  created() {
    this.getList()
    // getfuncName().then(res => {
    //   this.IsfuncName = res.data
    // })
  },
  mounted() {
    this.getTbHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTbHeight)
  },
  methods: {
    // 获取table高度的方法
    getTbHeight() {
      this.tableHeight = window.innerHeight - 120
    },
    getList() {
      this.listLoading = true
      getSalaryConfig().then(response => {
        let responseValues = response.data
        if (responseValues instanceof Array) {
          responseValues.forEach(element => {
            if (element.configType === "zeroAble") {

              if (element.isAble === '0') {
                this.zeroAble = false
              } else {
                this.zeroAble = true
              }

            }
            if (element.configType === "fileVerify") {
              //  this.fileVerify =this.formData[i].isAble
              if (element.isAble === '0') {
                this.fileVerify = false
              } else {
                this.fileVerify = true
              }
            }
            if (element.configType === "funcName") {
              //  this.fileVerify =this.formData[i].isAble
              if (element.isAble === '0') {
                this.funcName = false
              } else {
                this.funcName = true
              }
            }
            if (element.configType === "meritPay") {
              //  this.fileVerify =this.formData[i].isAble
              if (element.isAble === '0') {
                this.meritPay = false
              } else {
                this.meritPay = true
              }
            }

          });
        } else {
          this.fileVerify = false
          this.zeroAble = false
          this.funcName = false
          this.meritPay = false

          // this.zeroAbles = false
        }
        this.listLoading = false
      })
    },
    handleFilter() {
      this.getList()
    },
    toUpdate() {
      this.$refs['dataForm'].validate(valid => {

        if (valid) {
          this.toUpdateLoading = true
          const ListConfigCtrl = []
          const fileVerifys = {}
          fileVerifys['configType'] = "fileVerify"
          fileVerifys['isAble'] = this.fileVerify == false ? "0" : "1"
          fileVerifys['configTypeName'] = "是否校验附件"
          ListConfigCtrl.push(fileVerifys)
          const zeroAbles = {}
          zeroAbles['configType'] = "zeroAble"
          zeroAbles['isAble'] = this.zeroAble == false ? "0" : "1"
          zeroAbles['configTypeName'] = "为0上传"
          ListConfigCtrl.push(zeroAbles)
          const funcNames = {}
          funcNames['configType'] = "funcName"
          funcNames['isAble'] = this.funcName == false ? "0" : "1"
          funcNames['configTypeName'] = "开启支出功能科目"
          ListConfigCtrl.push(funcNames)
          const meritPays = {}
          meritPays['configType'] = "meritPay"
          meritPays['isAble'] = this.meritPay == false ? "0" : "1"
          meritPays['configTypeName'] = "绩效金额控制上报"
          ListConfigCtrl.push(meritPays)
          updataGetSalaryConfig(ListConfigCtrl).then(response => {
            this.dialogFormVisible = false
            this.$message({
              showClose: true,
              message: '保存成功',
              type: 'success',
              duration: 4000
            })
            this.toUpdateLoading = false
            this.handleFilter()
          })
        }
      })
    },
    deleteRedis(val) {
      const current = {}
      current['uuid'] = val
      this.deleteRedisLoading = true
      deleteRedis(current).then(response => {
        this.dialogFormVisible = false
        this.$message({
          showClose: true,
          message: '解锁成功',
          type: 'success',
          duration: 4000
        })

      })
      this.deleteRedisLoading = false
    }


  }
}
</script>

<style scoped lang="scss">
.left {
  margin-left: 100px;
}

.move {
  margin-top: 50px;
  margin-right: 50px;
}

.app-title {
  margin-bottom: 15px;
  height: 20px;
  border-bottom: 1px solid #dcdfe6;
}

.contentBorder {
  //box-shadow: 2px 2px 5px #e5e6eb;
  width: 90%;
  border: #a9eaa9 solid 1px;
  text-align: center;
  margin-left: 3%;

  .el-row:nth-child(1) {
    padding-top: 30px;

    .el-col:nth-child(1) {
      text-align: center;
    }

    .el-col:nth-child(3) {
      .el-input {
        margin-top: -10px;
      }
    }

    .el-col:nth-child(4) {
      text-align: right;
    }
  }

  .el-row:nth-child(2) {
    padding-top: 20px;
    padding-bottom: 30px;

    .el-col:nth-child(1) {
      text-align: right;
    }
  }

  .el-row:nth-child(3) {
    padding-top: 50px;
    padding-bottom: 30px;
    border-top: rgba(121, 121, 121, 1) solid 1px;

    .el-col:nth-child(1) {
      text-align: center;
    }

    .el-col:nth-child(3) {
      .el-input {
        margin-top: -10px;
        padding: 0px 5px 0px 10px;
      }
    }

    .el-col:nth-child(4) {
      text-align: right;
    }

  }
}
</style>
